;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname u4-huebung-a7) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp")))))
;; 7
;; contract:    sepia: image -> image
;; description: Makes a picture look old.
;; example:     (sepia (normal picture)) -> (same picture in old)

(define (sepia picture)
(local (
        ;; defines the colorlist of the picture
        (define loc-pic (image->color-list picture))
        
        ;; contract:    edit-color: color -> color
        ;; description: Makes a color look old.
        ;; example:     (edit-color (normal color)) -> (same color in old)
        (define (edit-color color)
          (local (
                  ;; Auxiliary definitions for the new color-elements.
                  (define old-red   (+ (* 0.393 (color-red color)) (* 0.769 (color-green color)) (* 0.189 (color-blue color))))
                  (define old-green (+ (* 0.349 (color-red color)) (* 0.686 (color-green color)) (* 0.168 (color-blue color))))
                  (define old-blue  (+ (* 0.272 (color-red color)) (* 0.534 (color-green color)) (* 0.131 (color-blue color)))))
            
            (make-color 
             (cond [(> 256 (round old-red))(round old-red)]
                             [else 255])
             (cond [(> 256 (round old-green))(round old-green)]
                             [else 255])
             (round old-blue)))))
  (color-list->image (map edit-color loc-pic) (image-width picture) (image-height picture) 0 0)))